<template>
    <a-drawer :title="props.drawerRecord && props.drawerRecord.name+'&nbsp;&nbsp;共&nbsp;'+dataSource.length+'&nbsp;条数据'" width="1400" placement="right" 
        v-model:visible="drawerVisible">
        <a-table :dataSource="dataSource" :columns="columns" bordered :pagination="false" rowKey="id">
            <template #index="{ index }">
                {{ index + 1 }}
            </template>

            <template #summaryType="{ record }">
                <span>
                    <a-tag color="#BDB76B" v-if="record.summaryType == 0">支部书记汇总</a-tag>
                    <a-tag color="#87d068" v-if="record.summaryType == 1">分管领导汇总</a-tag>
                </span>
            </template>
            <template #status="{ record }">
                <span>
                    <a-tag color="error" v-if="record.status == 0">待发送</a-tag>
                    <a-tag color="#87d068" v-if="record.status == 1">进行中</a-tag>
                    <a-tag v-if="record.status == 2">审核完毕</a-tag>
                </span>
            </template>

            <template #action="{ record }">
                <span>
                    <!-- <a-tag color="#87d068" v-if="record.status == 0" style="cursor: pointer;">启用</a-tag> -->
                    <!-- <a-tag color="error" v-if="record.status == 1 || record.status == 3" style="cursor: pointer;">停用</a-tag> -->
                    <a-tag color="#2db7f5" style="cursor: pointer;" @click="handleSend(record)" v-if="record.status == 0">发送</a-tag>
                    <a-tag color="#108ee9" style="cursor: pointer;" @click="handleShowDrawer(record)">详情</a-tag>
                </span>
            </template>
            
        </a-table>
    </a-drawer>
    <Drawer :drawerRecord="drawerRecord" ref="drawerRefs" />
    <a-modal v-model:visible="visible" title="提示" @ok="handleOk">
       <view style="display: flex;flex-direction: column;">
        <view style="color: #f00f00;"> 请注意！以下人员未完成上一阶段填报审核！提交后个人无法进行汇总!</view>
        <view style="color: #f00f00;"> 打分名单详情如下：</view>
        <br>
        <view >{{ modelText }} </view>
        <br>
        <view style="color: #f00f00;">是否继续发送？</view>

       </view>
    </a-modal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import Drawer from './components/Drawer.vue';
import { GetQuerySummaryDetails,PostCheckSubmit,PostSendSummaryLeader } from "@/api/main"
import { message } from 'ant-design-vue';
const dataSource = ref([])
const columns = [
    {
        title: '序号',
        dataIndex: 'index',
        key: 'index',
        align: "center",
        slots: { customRender: 'index' },
    },
    {
        title: '考核名称',
        dataIndex: 'assessmentName',
        key: 'assessmentName',
         align:"center"
    },
    {
        title: '审核人',
        dataIndex: 'reviewerName',
        key: 'reviewerName',
         align:"center"
    },
    
    {
        title: '创建时间',
        dataIndex: 'createdate',
        key: 'createdate',
         align:"center"
    },
    {
        title: '节点名称',
        dataIndex: 'nodeName',
        key: 'nodeName',
         align:"center"
    },
    {
        title: '汇总类型',
        dataIndex: 'summaryType',
        key: 'summaryType',
        slots: { customRender: 'summaryType' },
         align:"center"
    },
    {
        title: '流程状态',
        dataIndex: 'status',
        key: 'status',
        slots: { customRender: 'status' },
         align:"center"
    },
    {
        title: '操作',
        dataIndex: 'action',
        key: 'action',
        align: "center",
        slots: { customRender: 'action' },
    },
]
const drawerVisible = ref<boolean>(false);
const props = defineProps(["drawerRecord"]);
const detailsGetData = () => {
    setTimeout(() => {
        GetQuerySummaryDetails({
            assessmentId: props.drawerRecord.id
        }).then((response: any) => {
            dataSource.value = response.data
        })
    }, 500)
}
defineExpose({ drawerVisible, detailsGetData });

// 抽屉
const drawerRefs = ref();
const drawerRecord = ref(null)
const handleShowDrawer = (record: any) => {
    drawerRefs.value.drawerVisible = true;
    drawerRecord.value = record
    drawerRefs.value.detailsGetData()
}

const visible = ref<boolean>(false)
const modelText = ref<string>("")
const summaryId = ref(null)
// 发送
const handleSend = (record:any)=>{
    summaryId.value = record.id
    PostCheckSubmit({
        summaryId:record.id
    }).then((response:any)=>{
        visible.value = true
        modelText.value = response.data
    })
}
// 发送model 确认
const handleOk = ()=>{
    PostSendSummaryLeader({
        summaryId:summaryId.value
    }).then((response:any)=>{
        if(response.code==200){
            message.success(response.msg)
            detailsGetData()
            visible.value = false
        }else {
            message.error(response.msg)
        }
    })
}
</script>